package com.cxhc.app.api;


import com.cxhc.common.annotation.Anonymous;
import com.cxhc.common.core.domain.R;
import com.cxhc.common.utils.NanoIdUtils;
import com.cxhc.common.utils.QiniuUtils;
import com.cxhc.system.domain.app.HomeApp;
import com.cxhc.system.service.app.IHomeAppService;
import com.google.common.collect.ImmutableMap;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * 首页模块接口
 */
@RestController()
@RequestMapping("/api/upload")
@CrossOrigin(origins = "*", maxAge = 3600)
public class ApiUpload {

    @Resource
    private QiniuUtils qiniuUtils;


    /**
     * 单个上传请求（需授权）
     */
    @Anonymous
    @SneakyThrows
    @PostMapping("/authFile")
    public R<Map<String,String>> qiNiuUploadFile(MultipartFile file) {
        String key = NanoIdUtils.randomNanoId(10);
        String url = qiniuUtils.scyGet(file, key);
        return R.ok(ImmutableMap.of("url", url, "fileName", key));
    }

}
